#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> val(m);
  auto dp = vector(m, vector<__int128>(m, -1));
  auto dfs = [&](auto &self, int l, int r) {
    auto &res = dp[l][r];
    if (res != -1) return res;
    if (l == r) return res = val[l] * ((__int128)1 << m);
    return res = max(
      val[l] * ((__int128)1 << (m - (r - l))) + self(self, l + 1, r),
      val[r] * ((__int128)1 << (m - (r - l))) + self(self, l, r - 1)
    );
  };
  __int128 ans = 0;
  while (n--) {
    for (auto &v : val) cin >> v;
    dp = vector(m, vector<__int128>(m, -1));
    ans += dfs(dfs, 0, m - 1);
  }
  auto output = [&](auto &self, __int128 x) -> void {
    if (x >= 10) self(self, x / 10);
    putchar(x % 10 + '0');
  };
  output(output, ans);
}